import type { Http } from '@/utils/http'

/**
 * vue3 使用 TS，可以将接口调用模块化
 * 比如用户相关接口，可以统一定义在一个模块
 * vue2 接口调用分布在各个组件中
 * 备注：也可用 js 封装
 */
export default class UserApi {

    protected request: Http

    constructor(request: Http) {
        this.request = request
    }

    login<T>(args: { account: string, password: string }): Promise<T> {
        return this.request.postForm('auth/subscriber/login', { ...args, type: 1 })
    }

    querySysUserPage<T>(args: { account?: string, name?: string, phone?: string, status?: number, pageNum?: number, pageSize?: number }) {
        return this.request.get('manager/sysUser', args)
    }

    queryUserRole<T>(args: { userId: string, simple?: boolean }) {
        return this.request.get('manager/sysUser/role', args)
    }

    insertSysUser<T>(args: {}): Promise<any[]> {
        return this.request.postJson('manager/sysUser/insert', args)
    }

    updateSysUser<T>(args: {}): Promise<any[]> {
        return this.request.postJson('manager/sysUser/update', args)
    }

    resetSysUserPassword<T>(args: {}): Promise<any[]> {
        return this.request.postForm('manager/sysUser/resetPassword', args)
    }

    deleteSysUser<T>(args: {}): Promise<any[]> {
        return this.request.postForm('manager/sysUser/delete', args)
    }

}

const SysUserStatus = [
    {
        value: 0,
        label: '未激活'
    },
    {
        value: 1,
        label: '已激活'
    },
    {
        value: 9,
        label: '已删除'
    }
]

export { SysUserStatus }

